package com.benio.ycfdisplayer.fresco;

import android.graphics.Bitmap;
import android.view.View;

import com.benio.ycfdisplayer.displayer.SimpleDisplayListener;
import com.facebook.imagepipeline.image.CloseableBitmap;

/**
 * Implementation of {@link SimpleDisplayListener} for cases where the client wants access to a bitmap.
 * Created by zhangzhibin on 2016/12/29.
 */
public class BitmapDisplayListener extends SimpleDisplayListener {

    @Override
    public final void onSuccess(String imageUri, View view, Object loadedData) {
        Bitmap bitmap = null;
        if (loadedData instanceof Bitmap) {
            bitmap = (Bitmap) loadedData;
        } else if (loadedData instanceof CloseableBitmap) {
            bitmap = ((CloseableBitmap) loadedData).getUnderlyingBitmap();
        }
        onSuccess(imageUri, view, bitmap);
    }

    /**
     * Is called when image is loaded successfully (and displayed in View if one was specified)
     *
     * @param imageUri Loaded image URI
     * @param view     View for image. Can be <b>null</b>.
     * @param bitmap   Bitmap of your image.
     */
    public void onSuccess(String imageUri, View view, Bitmap bitmap) {

    }
}
